<?php
/**
 * User: wanghousheng
 * Date: 2017/8/26
 * Time: 16:12
 */
require_once 'AopClient.php';
require_once 'AlipayTradeAppPayRequest.php';
require_once 'config.php';
class Alipay_Lite{
        private $aop;
        private $notify_url;
        public function __construct($config){
            if (!$config['notify_url'] || !$config['app_id']) return false;
            $this->notify_url = $config['notify_url'];
            $this->aop = new  AopClient();
            $this->aop->gatewayUrl = "https://openapi.alipay.com/gateway.do";
            $this->aop->appId = $config['app_id'];
            $this->aop->rsaPrivateKey = PRIVATEKEY;
            $this->aop->alipayPublicKey= PUBLICKEY;
            $this->aop->format = "json";
            $this->aop->charset = "UTF-8";
            $this->aop->signType = "RSA2";
        }

    /**
     * Name: App支付接口返回支付信息
     * User: wanghousheng
     * Date: 2016/8/26
     * @param $pay_sn
     * @param $order_money
     * @param $order_name
     * @return string
     */
        public function DoPay($pay_sn,$order_money,$order_name){
            if ($pay_sn && $order_money && $order_name){
                $parms['body'] =$order_name;
                $parms['subject'] =$order_name;
                $parms['out_trade_no'] = $pay_sn;
                $parms['timeout_express'] = '30m';
                $parms['total_amount'] = $order_money;
                $parms['product_code'] = 'QUICK_MSECURITY_PAY';
                $bizcontent = json_encode($parms);
                $request = new  AlipayTradeAppPayRequest();
                $request->setNotifyUrl($this->notify_url);
                $request->setBizContent($bizcontent);
                $response = $this->aop->sdkExecute($request);
                return $response;
            }
        }
}